package com.hfuuTaf.frontData;

import com.hfuuTaf.mapper.registerMapper;
import com.hfuuTaf.pojo.register;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.Objects;

@Controller
@RequestMapping("/data")
public class dataController {
    private final registerMapper registerMapper;

    public dataController(registerMapper registerMapper) {
        this.registerMapper = registerMapper;
    }

    @PostMapping("/post/addClubMember")
    public String addMan(
            @RequestParam("name") String name,
            @RequestParam("stuId") String stuId,
            @RequestParam("radioSex") String sex,
            @RequestParam("phone") String phone,
            @RequestParam("major") String major,
            @RequestParam("college") String college,
            @RequestParam("message") String message

    ) {
        register register = new register();
        register.setName(name);
        register.setStudentId(stuId);
        register.setPhone(phone);
        register.setSex(Objects.equals(sex, "男") ?1:0);
        register.setMajor(major);
        register.setDepartment(college);
        register.setIntroduce(message);
        register.setDate(new Date());

        int insert = registerMapper.insert(register);
        if(insert==1){
            return "redirect:/addSuccess";
        }else{
            return "redirect:/addFail";
        }

    }

}
